package com.ys.controller.web.overseas;

import com.ys.config.MenuId;
import com.ys.dto.SubGridConfigDto;
import com.ys.entity.overseas.TosProductBasis;
import com.ys.entity.purchase.TcgPurchaseAddress;
import com.ys.entity.purchase.TcgPurchaseByPlan;
import com.ys.entity.sys.TsUserChange;
import com.ys.service.overseas.TosProductBasisService;
import com.ys.service.sys.CommonApiService;
import com.ys.util.shiro.ShiroUtils;
import com.ys.vo.Flow;
import com.ys.vo.W;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;

/**
 * HW商品库
 */
@Controller
@RequestMapping("/web/overseas/tosProductBasis")
public class WebTosProductBasisController {
	private static final Logger logger = LoggerFactory.getLogger(WebTosProductBasisController.class);

	@Autowired
	private CommonApiService<TosProductBasis> commonApiService;

    @Autowired
    private TosProductBasisService tosProductBasisService;

    private final Long MENU_ID = MenuId.TOS_ProductBasis;

    /*
     * 新增
     */
    @GetMapping("/toAdd")
    public String toAdd(Model model, HttpServletRequest request, HttpServletResponse response) {
        try {
            Map<String, Object> extraParam = new HashMap<>();
            //关联数据
            extraParam.put("status", 1);

            TosProductBasis entity = new TosProductBasis();
            //商品编码
            String code = commonApiService.getCommonNextUkey(MENU_ID,"Code");
            //entity.setBid(bid);
            extraParam.put("code", code);

            TsUserChange tsUserChange = new TsUserChange().setUserId(ShiroUtils.getUserId()).setStatus(1).queryFirst();
            if(tsUserChange!=null){
                extraParam.put("_ys_createUserName", tsUserChange.getUserId()+"/"+tsUserChange.getUserName());//制单人信息
            }



            // 子列表配置信息
            commonApiService.toAdd(model, entity, MENU_ID, extraParam, null);
            return "overseas/tosProductBasis/toAdd";
        }catch (Exception e) {
            logger.error("新增页面出错：",e.getMessage(),e);
            return W.error(model, e.getMessage());
        }
    }

    /*
     * 编辑
     */
    @GetMapping("/toEdit")
    public String toEdit(Model model, HttpServletRequest request, HttpServletResponse response, long id) {
        try {

            Map<String, Object> extraParam = tosProductBasisService.getExtraParam(id);

            commonApiService.toEdit(model,Long.parseLong(extraParam.get("id").toString()), new TosProductBasis(), MENU_ID, extraParam, null);
            return "purchase/tcgPurchasePlan/toEdit";

        }catch (Exception e) {
            logger.error("编辑页面出错：",e.getMessage(),e);
            return W.error(model, e.getMessage());
        }
    }




}






